import 'package:accumulation/widget/time_selector/time_selector.dart';
import 'package:accumulation/widget/time_selector/time_selector_data.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class TimeSelectorPage extends StatefulWidget {

  @override
  _TimeSelectorState createState() => _TimeSelectorState();

}

class _TimeSelectorState extends State<TimeSelectorPage> {

  List<DayTimeEntity> _dayTime;
  String _result;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _dayTime = getDayTime(days: 4);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text('仿叮咚买菜的时间段选择'),
        ),
        body: Container(
          width: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Expanded(
                flex: 2,
                child: Container(),
              ),
              Text(_result ?? '请选择时间'),
              Expanded(
                flex: 1,
                child: Container(),
              ),
              CupertinoButton(
                child: Text('时间选择'),
                color: Colors.blue,
                onPressed: (){
                  showModalBottomSheet(context: context,
                      builder: (BuildContext context) {
                        return TimeSelector(timeData: _dayTime);
                      }).then((value) {
                    String result = value;
                    if(result != null && result.isNotEmpty) {
                      setState(() {
                        _result = result;
                      });
                    }
                  });
                },
              ),
              Expanded(
                flex: 4,
                child: Container(),
              ),
            ],
          ),
        )
    );
  }

}